<template>
  <div
      style="height: 100vh;width: 100%;background-size: cover;display: flex;align-items: center;justify-content: center">
    <div style="width: 30%;height: 40vh;align-items: center;display: flex;flex-direction: column">
      <span> 登陆</span>
      <br>
      <div>
        <el-input v-model="name" placeholder="账号"/>
      </div>
      <br>
      <div>
        <el-input v-model="password" type="password" placeholder="密码"/>
      </div>
      <br>
      <div style="display: flex;flex-direction: row">
        <el-button @click="login" type="primary" >登陆</el-button>

      </div>
    </div>

  </div>
</template>

<script>
import axios from "axios";


export default {
  name: "login",
  data(){
    return{
      name:'',
      password:''
    }

  },
  methods:{

    login(){
      axios.post("http://localhost:9090/user/login",{
        name:this.name,
        password:this.password

      }).then(res=>{
        let  data=res.data
        if(data.state=="ok"){
          localStorage.setItem("name",this.name)
          this.$router.push({
            name:'index'
          })
        }else {
          this.$message.error('登陆错误');


        }

      })

    }
  }
}
</script>

<style scoped>

</style>